# -*- coding: utf-8 -*-
# @Author : HaleShi
# @Time : 2023-09-05
# @File : 1_Spider.py

import requests
import json
import time
from uuid import uuid4

# today.tophub.app.bac

t = int(time.time())
uuid = uuid4()
headers = {
    "accept": "application/vnd.tophub.v1+json",
    "user-agent": "TophubApp/1.0 Mozilla/5.0 (Linux; Android 11; Pixel 2 XL Build/RP1A.201005.004.A1; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/116.0.0.0 Mobile Safari/537.36",
    "x-network-type": "NETWORK_WIFI",
    "x-app-version": "18",
    "authorization": "592929103392b6c1835ea83e245dcfd3",
    "x-app-package-name": "today.tophub.app.bac",
    "x-app-version-name": "1.9.3",
    "x-device-uuid": "164051e9f063e7976e5bc23397460a1f",
    "x-device-model": "Pixel2XL",
    "x-device-udid": "164051e9-f063-3797-ae5b-c23397460a1f",
    "accept-encoding": "gzip"
}

param_dict = {
    "nonce": "XCZYdXdnxx5oypUk",
    "p": "2",
    "sign": "ba6bb7236e2917586ea768dac7133c62",
    "timestamp": "1693884370"
}

# body_dict = {
#
# }

# res = requests.get(
#     headers=headers,
#     url="https://api2.tophub.app/my/items",
#     params=param_dict,
#     # data=body_dict
# )
# print(res.json())

with open("./my_item.json", "r", encoding="utf-8") as r:
    res = r.read()
    content = json.loads(res)
for index, c_c in enumerate(content["data"]["items"]):
    print(index, c_c["domain"], c_c["title"], c_c["url"])
